var t = require("../common").minutesToTimeEl, e = getApp(), a = e.getNetAddresss("plugin.free-lottery.frontend.lottery.wait"), o = e.getNetAddresss("plugin.free-lottery.frontend.lottery"), n = null;

Page({
    data: {
        prizies: [ {
            text: "谢谢参与"
        }, {
            text: "免单"
        }, {
            text: "谢谢参与"
        }, {
            text: "免单"
        }, {
            text: "谢谢参与"
        }, {
            text: "免单"
        }, {
            text: "谢谢参与"
        }, {
            text: "免单"
        }, {
            text: "谢谢参与"
        }, {
            text: "免单"
        } ],
        pageLoaded: !1,
        hiddenResultPopup: !0,
        startSprnning: !1,
        isLottery: !1,
        showFooterButtons: !1,
        luckyNumber: 0,
        orders: [],
        orderId: null,
        task: {},
        freeTasks: [],
        lotteryPopupClass: "",
        turntableSprnned: !1
    },
    onLoad: function(t) {
        if (!t.order_ids) return wx.showToast({
            title: "订单不存在",
            icon: "none"
        }), void setTimeout(function() {
            wx.navigateBack();
        }, 1e3);
        wx.showLoading({
            title: "订单支付中"
        }), this.pollingConfirmPay(1e3, t.order_ids), this.checkConfirmPay(t.order_ids), 
        this.setData({
            orderId: t.order_ids
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        clearInterval(n), n = null;
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            path: "/packageG/index/index?mid=" + wx.getStorageSync("yz_uid")
        };
    },
    turntabeEnd: function(t) {
        var e = this;
        this.setData({
            turntableSprnned: !0
        }), setTimeout(function() {
            e.setData({
                hiddenResultPopup: !1
            });
        }, 300);
    },
    displayResultPopup: function() {
        !0 === this.data.turntableSprnned && !0 === this.data.pageLoaded && this.setData({
            hiddenResultPopup: !this.data.hiddenResultPopup
        });
    },
    lottery: function() {
        var a = this;
        e._getNetWork({
            url: o,
            data: {
                order_ids: this.data.orderId
            },
            success: function(e) {
                var o = e.data, n = o.data, s = o.result, i = o.msg;
                if (0 !== s) {
                    n.task.limit_day = Number(n.task.limit_time / 1440).toFixed(1), n.task.limit_str = t(n.task.limit_time);
                    var r = "lottery-popup_lost";
                    !0 === n.status && (1 === n.task.status || -1 === n.task.status ? r = "" : 0 === n.task.status && (r = "lottery-popup_first")), 
                    a.setData({
                        luckyNumber: !0 === n.status ? 2 : 3
                    }, function() {
                        a.setData({
                            luckyNumber: !0 === n.status ? 2 : 3,
                            startSprnning: !0,
                            isLottery: n.status,
                            freeTasks: n.dividend,
                            task: n.task,
                            lotteryPopupClass: r,
                            pageLoaded: !0,
                            showFooterButtons: n.status && 0 === n.task.status
                        });
                    }), wx.setNavigationBarTitle({
                        title: n.plugin_name
                    });
                } else wx.showToast({
                    title: i,
                    icon: "none"
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: t.msg || t.message,
                    icon: "none"
                });
            }
        });
    },
    pollingConfirmPay: function() {
        var t = this, e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 3e3, a = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : this.data.orderId;
        n = setInterval(function() {
            t.checkConfirmPay(a);
        }, e);
    },
    checkConfirmPay: function() {
        var t = this, o = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : this.data.orderId;
        e._getNetWork({
            url: a,
            data: {
                order_ids: o
            },
            success: function(e) {
                e.data.data.status && (wx.hideLoading(), clearInterval(n), n = null, t.lottery());
            }
        });
    },
    toRecords: function() {
        wx.navigateTo({
            url: "/packageH/free_of_charge/FreeRecord/FreeRecord"
        });
    }
});